<template>
	<view class="container">

		<!-- 酒店信息 -->
		<view class="hotel-info">
			<view class="hotel-content">
				<view class="hotel-main">
					<text class="hotel-name">{{info.name}}</text>
					<view></view>
					<text class="hotel-address" style="color: #333333;">{{info.bedInfo}}</text>
					<view></view>
					<text class="hotel-address">{{start}}~{{end}}</text>
				</view>
				<image class="hotel-image" :src="info.picture" mode="aspectFill" />
			</view>
		</view>
		<!-- 预订详情 -->
		<view class="booking-detail">
			<view class="detail-item">
				<text class="detail-label">您的姓名<text style="color: #FF4D4F;">*</text></text>
				<input class="detail-input" v-model="form.name" type="text" placeholder="请输入您的姓名" />
			</view>
			<view class="detail-item">
				<text class="detail-label">您的电话<text style="color: #FF4D4F;">*</text></text>
				<input class="detail-input" v-model="form.phone" type="text" placeholder="请输入您的电话" />
			</view>
			<view class="detail-item">
				<text class="detail-label">入住人数<text style="color: #FF4D4F;">*</text></text>
				<input class="detail-input" v-model="form.roomCount" type="number" placeholder="请输入入住人数" />
			</view>
			<view class="detail-item">
				<text class="detail-label">预订房间数<text style="color: #FF4D4F;">*</text></text>
				<input class="detail-input" v-model="form.roomCount" type="number" disabled placeholder="请输入预订房间数" />
			</view>
			<view class="detail-item">
				<text class="detail-label">您的备注</text>
				<input class="detail-input" v-model="form.remark" type="text" placeholder="请输入您的备注" />
			</view>
		</view>
		<!-- 温馨提示 -->
		<view class="notice">
			<text class="notice-title">温馨提示</text>
			<view class="notice-content">
				<text class="notice-item">• 请在入住时出示有效身份证件</text>
				<text class="notice-item">• 如需提前入住或延迟退房请提前与酒店联系</text>
				<text class="notice-item">• 入住前24小时内取消将收取首晚房费</text>
			</view>
		</view>
		<!-- 底部按钮 -->
		<view class="bottom-buttons">
			<view class="bottom-price">
				<text class="price-symbol">¥</text>
				<text class="price-amount">{{Number(info.price).toFixed(2)}}</text>
			</view>
			<view @click="reservation" class="book-button">立即预约</view>
		</view>
	</view>
</template>
<script>
	import {
		BASE_URL_ZJ
	} from '@/api/config';
	
	export default {
		data() {
			return {
				info: {},
				start: '',
				end: '',
				form: {
					name: '',
					phone: '',
					peopleCount: 1,
					roomCount: 1,
					remark: ''
				}
			}
		},

		onLoad(options) {
			this.getDetail(options.id);
			this.start = options.start;
			this.end = options.end;
		},

		methods: {
			getDetail(id) {
				uni.request({
					url: BASE_URL_ZJ + '/roomType/byId/' + id,
					method: 'GET',
					success: res => {
						this.info = res.data.data;
					}
				})
			},
			
			reservation() {
				if (!this.form.name || !this.form.phone) {
					return uni.showToast({
						title: '请完善信息',
						icon: 'none'
					});
				}
				uni.request({
					url: BASE_URL_ZJ + '/bookingRecord/add',
					method: 'POST',
					data: {
						amount: this.info.price,
						customerName: this.form.name,
						customerPhone: this.form.phone,
						remark: this.form.remark,
						roomCount: this.form.roomCount,
						peopleCount: this.form.peopleCount,
						roomTypeId: this.info.id,
						roomTypeName: this.info.name,
						fromTime: this.start + ' ' + '00:00:00',
						toTime: this.end + ' ' + '23:59:59',
						bookingStatus: 1
					},
					success: res => {
						this.openSuccess();
					}
				})
			},
			
			openSuccess() {
				uni.navigateTo({
					url: `/pages/hotel/success?info=${JSON.stringify({
						name: this.info.name,
						bedInfo: this.info.bedInfo,
						userName: this.form.name,
						phone: this.form.phone,
						price: this.info.price,
						remark: this.form.remark,
						roomCount: this.form.roomCount,
						roomTypeId: this.info.id,
						start: this.start + ' ' + '00:00:00',
						end: this.end + ' ' + '23:59:59',
					})}`
				})
			},
		}
	}
</script>
<style>
	page {
		height: 100%;
		background-color: #F5F5F5;
	}

	.container {
		display: flex;
		flex-direction: column;
		padding-bottom: 120rpx;
	}

	.hotel-info {
		margin: 20rpx;
		padding: 30rpx;
		background-color: #FFFFFF;
		border-radius: 12rpx;
	}

	.hotel-content {
		display: flex;
		justify-content: space-between;
		gap: 20rpx;
	}

	.hotel-main {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.hotel-name {
		font-size: 20px;
		font-weight: 600;
		color: #333333;
	}

	.hotel-rating {
		display: flex;
		align-items: center;
		gap: 10rpx;
		margin-bottom: 16rpx;
	}

	.rating-text {
		font-size: 14px;
		color: #666666;
	}

	.hotel-address {
		font-size: 14px;
		color: #999999;
	}

	.hotel-image {
		width: 160rpx;
		height: 160rpx;
		border-radius: 8rpx;
	}

	.booking-detail {
		margin: 20rpx;
		padding: 30rpx;
		background-color: #FFFFFF;
		border-radius: 12rpx;
	}

	.detail-item {
		display: flex;
		justify-content: space-between;
		margin-bottom: 20rpx;
	}

	.detail-item:last-child {
		margin-bottom: 0;
	}

	.detail-label {
		font-size: 14px;
		color: #666666;
	}

	.detail-value {
		font-size: 14px;
		color: #333333;
	}

	.detail-input {
		font-size: 14px;
		color: #333333;
		text-align: right;
		padding: 4rpx 0;
		width: 300rpx;
	}

	.detail-picker {
		width: 300rpx;
	}

	.picker-text {
		font-size: 14px;
		color: #999999;
		text-align: right;
	}

	.payment-info {
		margin: 20rpx;
		padding: 30rpx;
		background-color: #FFFFFF;
		border-radius: 12rpx;
	}

	.price-section {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-bottom: 30rpx;
		border-bottom: 1px solid #EEEEEE;
	}

	.price-label {
		font-size: 16px;
		color: #333333;
	}

	.price-value {
		font-size: 24px;
		font-weight: 600;
		color: #FF4D4F;
	}

	.payment-detail {
		margin-top: 30rpx;
	}

	.payment-item {
		display: flex;
		justify-content: space-between;
		margin-bottom: 20rpx;
	}

	.payment-label {
		font-size: 14px;
		color: #666666;
	}

	.payment-status {
		font-size: 14px;
		color: #07C160;
	}

	.order-number {
		display: flex;
		align-items: center;
		gap: 10rpx;
	}

	.number-text {
		font-size: 14px;
		color: #333333;
	}

	.payment-method {
		font-size: 14px;
		color: #333333;
	}

	.notice {
		margin: 20rpx;
		padding: 30rpx;
		background-color: #FFFFFF;
		border-radius: 12rpx;
	}

	.notice-title {
		font-size: 16px;
		font-weight: 500;
		color: #333333;
		margin-bottom: 20rpx;
	}

	.notice-content {
		display: flex;
		flex-direction: column;
		gap: 16rpx;
	}

	.notice-item {
		font-size: 14px;
		color: #666666;
		line-height: 1.5;
	}

	.bottom-buttons {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		padding: 20rpx;
		background-color: #FFFFFF;
		box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.05);
		display: flex;
		align-items: center;
		justify-content: space-between;
		z-index: 100;
	}

	.bottom-price {
		display: flex;
		align-items: baseline;
	}

	.price-symbol {
		font-size: 16px;
		color: #FF4D4F;
		margin-right: 4rpx;
	}

	.price-amount {
		font-size: 24px;
		font-weight: 600;
		color: #FF4D4F;
	}

	.book-button {
		background-color: #FF4D4F;
		color: #FFFFFF;
		padding: 20rpx 60rpx;
		border-radius: 40rpx;
		font-size: 16px;
	}
</style>